import 'package:flutter_menu/app_config.dart';
import 'package:flutter_menu/biz/setting/setting_controller.dart';
import 'package:flutter_menu/res/app_design.dart';
import 'package:get/get.dart';


class SettingPg extends GetView<SettingController> {


  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      child: GetBuilder<SettingController>(
          init: controller,
          builder: (controller) =>SafeArea(child: body(context).whitScaffold())),
    );
  }

  Widget body(BuildContext context) {
    var model =  AppConfig.instance.loginModel;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text("${getString(model?.nickName)} ${getString(model?.username)}",style: TextStyle(fontSize: 25.sp),).size(width: double.infinity).marginOnly(left: 24.w),
        Text(getString(controller.shopModel?.name),style: TextStyle(fontSize: 40.sp),).marginOnly(top: 148.w),
        _content().expanded(),
       Row(
         children: [
           Text(
              "V  ${controller.version}",
              style: TextStyle(fontSize: AppDimen.sp_25, color: const Color(0xFF4A230A)),
            ).marginOnly(bottom: 34.w,left: 24.w ),
         ],
       ),
      ],
    ).size(width: double.infinity);
  }


  GridView _content(){
   List<GVItem> items =   controller.items;
    return GridView.builder(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        childAspectRatio: 1.0,
      ),
      itemCount: items.length,
      itemBuilder: (context, index) {
        GVItem item = items[index];
        String? icon  =item.icon;
        return Stack(
          children: [
            if(icon != null) Positioned(
              right: 81.w,
                top: 23.w,
                child: Image.asset(icon,height: 44.w,)),
            GestureDetector(
              onTap: (){
                item.onTap?.call(item,index);
              },
              child: Column(
                children: [
                  Image.asset(item.imgUrl,height: 108.w,).marginOnly(top: 52.w),
                  Text(item.name,style: TextStyle(fontSize: AppDimen.sp_24),).marginOnly(top: 39.w)
                ],
              ).center(),
            )
          ],
        );
      },
    );
  }




}